using Assets.Scripts.GDK;
using SimpleJson;
using System;
using UnityEngine;


namespace Brick
{
	public class AdvansBoxMoudle : gdk_base_Imodule
	{
		private DateTime lastplaytime;

		private DateTime lastXPplaytime;

		private int enterLevelTimes;

		private int playAdTimes;

		private string lastAdType = string.Empty;

		private Vector2 realSize = Vector2.zero;

		private int scaleIos;

		public void PlayAD(string ID, string type, Action cbBack, Action failBack)
		{
			if (!true)
			{
				if (cbBack != null)
				{
					cbBack();
				}
				return;
			}
			if (!(ID == Advans.YULANADDBALL) && !(ID == Advans.STOREPLAY) && !(ID == Advans.SHOPPLAY) && !(ID == Advans.FUHUOGAME) && !(ID == Advans.SIGNDOUBLE))
			{
				if (GameData.closeAD)
				{
					if (cbBack != null)
					{
						cbBack();
					}
					return;
				}
				if (GameData.selectIndex < GameManager.getStartLevel())
				{
					if (cbBack != null)
					{
						cbBack();
					}
					return;
				}
				if (GameData.selectIndex >= GameManager.getAllStartLevel())
				{
					if ((enterLevelTimes % GameManager.getJianGe2() != 0 || enterLevelTimes == 0) && cbBack != null)
					{
						cbBack();
					}
				}
				else if (enterLevelTimes % GameManager.getJianGe1() != 0 || enterLevelTimes == 0)
				{
					if (cbBack != null)
					{
						cbBack();
					}
					return;
				}
				DateTime now = DateTime.Now;
				if (!(now.TimeOfDay.TotalSeconds - lastXPplaytime.TimeOfDay.TotalSeconds > (double)GameManager.getJiangeTime()))
				{
					gdk_game_manager.log("10s内不播插屏");
					if (cbBack != null)
					{
						cbBack();
					}
					return;
				}
				lastXPplaytime = now;
				if (lastAdType == type)
				{
					playAdTimes++;
				}
				else
				{
					playAdTimes = 0;
				}
				if (playAdTimes >= 2)
				{
					type = GameManager.getOtherAdType(type);
				}
				lastAdType = type;
			}
			GameManager.PlayAdvert(ID, type, delegate
			{
				gdk_game_manager.log("视频完成");
				if (cbBack != null)
				{
					cbBack();
				}
			}, delegate
			{
				gdk_game_manager.log("广告遇到其它类型错误失败");
				if (failBack != null)
				{
					failBack();
				}
			}, delegate
			{
				gdk_game_manager.log("视频取消");
				if (failBack != null)
				{
					failBack();
				}
			}, string.Empty);
		}

		public string getOtherType(string curType)
		{
			if (curType == "8")
			{
				return curType;
			}
			if (curType == "4")
			{
				return curType;
			}
			if (curType == "2")
			{
				return curType;
			}
			return curType;
		}

		public void OnEnterGame()
		{
			enterLevelTimes++;
		}

		/*public void PlayBanner()
		{
			if (GameManager.IsOpenAd() && !GameData.closeAD)
			{
				JsonObject jsonObject = new JsonObject();
				AdSize adSize = new AdSize();
				jsonObject.Add("rect", adSize);
				jsonObject.Add("fitMode", 2);
				jsonObject.Add("designWidth", 720);
				jsonObject.Add("designHeight", 1280);
				if (scaleIos == 0)
				{
					gdk_game_manager.log(">>> hehe >>>");
					scaleIos = 2;
				}
				adSize.width = 320 * scaleIos;
				adSize.height = 50 * scaleIos;
				adSize.x = realSize.x / 2f - adSize.width / 2f;
				jsonObject.Add("realWidth", realSize.x);
				jsonObject.Add("realHeight", realSize.y);
				jsonObject.Add("extra", new JsonObject());
				string extrainfo = SimpleJson.SimpleJson.SerializeObject(jsonObject);
				GameManager.PlayAdvert(Advans.GAMEBANNER, "1", delegate
				{
				}, delegate
				{
					gdk_game_manager.log("广告遇到其它类型错误失败");
				}, delegate
				{
					gdk_game_manager.log("视频取消");
				}, extrainfo);
			}
		}*/

		/*public void HideBanner()
		{
			if (GameManager.IsOpenAd() && !GameData.closeAD)
			{
				SDKManager.RemoveAdvert(Advans.GAMEBANNER, null);
			}
		}*/

		public void GetRealSize()
		{
			//string designSize = SDKManager.GetDesignSize();
			//string[] array = designSize.ToString().Split('x');
			/*gdk_game_manager.log("cellArr " + array);
			if (array.Length == 2)
			{
				gdk_game_manager.log("cell 1" + array[0]);
				gdk_game_manager.log("cell 2" + array[1]);
				int num = Convert.ToInt32(array[0]);
				int num2 = Convert.ToInt32(array[1]);
				realSize = new Vector2(num, num2);
			}*/
		}

		public void GetScale()
		{
			/*string scale = SDKManager.GetScale();
			if (scale == string.Empty)
			{
				scaleIos = 1;
				return;
			}
			JsonObject jsonObject = (JsonObject)SimpleJson.SimpleJson.DeserializeObject(scale);
			scaleIos = Convert.ToInt32(jsonObject["scale"]);
			gdk_game_manager.log(">>>>scale " + scaleIos);*/
		}
	}
}

